﻿using AMatysiak.Controls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace AMatysiakTest
{
    [TestClass]
    public class ValueBarTest
    {
        [TestMethod]
        public void testProperties()
        {
            ValueBar bar = new ValueBar();
            bar.Min = 0;
            bar.Max = 10;
            bar.Step = 1;
            bar.Value = 5;

            Assert.AreEqual(0, bar.Min);
            Assert.AreEqual(10, bar.Max);
            Assert.AreEqual(1, bar.Step);
            Assert.AreEqual(5, bar.Value);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void testValueOverflow()
        {
            ValueBar bar = new ValueBar();
            bar.Min = 0;
            bar.Max = 10;
            bar.Step = 1;
            bar.Value = 11;
        }

        [TestMethod]
        public void testChangingMaxConstraintWhenValueIsEqualToMax()
        {
            ValueBar bar = new ValueBar();
            bar.Min = 0;
            bar.Max = 100;
            bar.Step = 0.5;
            bar.Value = 100;

            bar.Max -= 30;

            Assert.AreEqual(70, bar.Value);
        }

        [TestMethod]
        public void testChangingMaxConstraintWhenValueIsSmallerThenMax()
        {
            ValueBar bar = new ValueBar();
            bar.Min = 0;
            bar.Max = 100;
            bar.Step = 0.5;
            bar.Value = 60;

            bar.Max -= 30;

            Assert.AreEqual(60, bar.Value);
        }

        [TestMethod]
        public void testChangingMinConstraint()
        {
            ValueBar bar = new ValueBar();
            bar.Min = 10;
            bar.Max = 100;
            bar.Step = 0.5;
            bar.Value = 11;

            bar.Min = -10;

            Assert.AreEqual(11, bar.Value);
        }

        [TestMethod]
        public void testChangingStepConstraint()
        {
            ValueBar bar = new ValueBar();
            bar.Min = 10;
            bar.Max = 100;
            bar.Step = 0.5;
            bar.Value = 15;

            bar.Step = 5;

            Assert.AreEqual(15, bar.Value);
        }

    }
}
